package cn.kgc.springcloud.web.controller;

import cn.kgc.springcloud.web.entity.Tag;
import cn.kgc.springcloud.web.response.ResponseResult;
import cn.kgc.springcloud.web.service.TagService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/7/29
 * @description
 */
@RestController
@RequestMapping("tag")
public class TagController {

    @Resource
    private TagService tagService;

    @GetMapping
    public ResponseResult tagList(){
        List<Tag> list = tagService.list();
        return ResponseResult.success().data(list);
    }


    @GetMapping("{id}")
    public Tag getOneTag(@PathVariable("id") Integer id){
        Tag tag = tagService.getById(id);
        return tag;
    }

    @PostMapping
    public ResponseResult addTag(@RequestBody Tag tag){

        tagService.save(tag);
        return ResponseResult.success().data(tag);
    }


    @DeleteMapping("{id}")
    public ResponseResult deleteTag(@PathVariable("id") Integer id){
        tagService.removeById(id);
        return ResponseResult.success();
    }


}
